home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / info / diff.info-2 (.txt) < prev    next >
GNU Info File  |  1995-07-29  |  50KB  |  945 lines

  1. This is Info file diff.info, produced by Makeinfo-1.55 from the input
  2. file ./diff.texi.
  3.    This file documents the the GNU `diff', `diff3', `sdiff', and `cmp'
  4. commands for showing the differences between text files and the `patch'
  5. command for using their output to update files.
  6.    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  7.    Permission is granted to make and distribute verbatim copies of this
  8. manual provided the copyright notice and this permission notice are
  9. preserved on all copies.
  10.    Permission is granted to copy and distribute modified versions of
  11. this manual under the conditions for verbatim copying, provided that
  12. the entire resulting derived work is distributed under the terms of a
  13. permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that this permission notice may be stated in a
  17. translation approved by the Foundation.
  18. File: diff.info,  Node: Line Formats,  Next: Detailed If-then-else,  Prev: Line Group Formats,  Up: If-then-else
  19. Line Formats
  20. ------------
  21.    Line formats control how each line taken from an input file is
  22. output as part of a line group in if-then-else format.
  23.    For example, the following command outputs text with a one-column
  24. change indicator to the left of the text.  The first column of output
  25. is `-' for deleted lines, `|' for added lines, and a space for
  26. unchanged lines.  The formats contain newline characters where newlines
  27. are desired on output.
  28.      diff \
  29.         --old-line-format='-%l
  30.      ' \
  31.         --new-line-format='|%l
  32.      ' \
  33.         --unchanged-line-format=' %l
  34.      ' \
  35.         old new
  36.    To specify a line format, use one of the following options.  You
  37. should quote FORMAT, since it often contains shell metacharacters.
  38. `--old-line-format=FORMAT'
  39.      formats lines just from the first file.
  40. `--new-line-format=FORMAT'
  41.      formats lines just from the second file.
  42. `--unchanged-line-format=FORMAT'
  43.      formats lines common to both files.
  44.    In a line format, ordinary characters represent themselves;
  45. conversion specifications start with `%' and have one of the following
  46. forms.
  47.      stands for the the contents of the line, not counting its trailing
  48.      newline (if any).  This format ignores whether the line is
  49.      incomplete; *Note Incomplete Lines::.
  50.      stands for the the contents of the line, including its trailing
  51.      newline (if any).  If a line is incomplete, this format preserves
  52.      its incompleteness.
  53.      stands for a null character.
  54.      stands for `%'.
  55.    The default line format is `%l' followed by a newline character.
  56.    If the input contains tab characters and it is important that they
  57. line up on output, you should ensure that `%l' or `%L' in a line format
  58. is just after a tab stop (e.g. by preceding `%l' or `%L' with a tab
  59. character), or you should use the `-t' or `--expand-tabs' option.
  60. File: diff.info,  Node: Detailed If-then-else,  Next: Example If-then-else,  Prev: Line Formats,  Up: If-then-else
  61. Detailed Description of If-then-else Format
  62. -------------------------------------------
  63.    For lines common to both files, `diff' uses the unchanged line group
  64. format.  For each hunk of differences in the merged output format, if
  65. the hunk contains only lines from the first file, `diff' uses the old
  66. line group format; if the hunk contains only lines from the second
  67. file, `diff' uses the new group format; otherwise, `diff' uses the
  68. changed group format.
  69.    The old, new, and unchanged line formats specify the output format of
  70. lines from the first file, lines from the second file, and lines common
  71. to both files, respectively.
  72.    The option `--ifdef=NAME' is equivalent to the following sequence of
  73. options using shell syntax:
  74.      --old-group-format='#ifndef NAME
  75.      %<#endif /* not NAME */
  76.      ' \
  77.      --new-group-format='#ifdef NAME
  78.      %>#endif /* NAME */
  79.      ' \
  80.      --unchanged-group-format='%=' \
  81.      --changed-group-format='#ifndef NAME
  82.      %<#else /* NAME */
  83.      %>#endif /* NAME */
  84.      '
  85.    You should carefully check the `diff' output for proper nesting.
  86. For example, when using the the `-D NAME' or `--ifdef=NAME' option, you
  87. should check that if the differing lines contain any of the C
  88. preprocessor directives `#ifdef', `#ifndef', `#else', `#elif', or
  89. `#endif', they are nested properly and match.  If they don't, you must
  90. make corrections manually.  It is a good idea to carefully check the
  91. resulting code anyway to make sure that it really does what you want it
  92. to; depending on how the input files were produced, the output might
  93. contain duplicate or otherwise incorrect code.
  94.    The `patch' `-D NAME' option behaves just like the `diff' `-D NAME'
  95. option, except it operates on a file and a diff to produce a merged
  96. file; *Note patch Options::.
  97. File: diff.info,  Node: Example If-then-else,  Prev: Detailed If-then-else,  Up: If-then-else
  98. An Example of If-then-else Format
  99. ---------------------------------
  100.    Here is the output of `diff -DTWO lao tzu' (*note Sample diff
  101. Input::., for the complete contents of the two files):
  102.      #ifndef TWO
  103.      The Way that can be told of is not the eternal Way;
  104.      The name that can be named is not the eternal name.
  105.      #endif /* not TWO */
  106.      The Nameless is the origin of Heaven and Earth;
  107.      #ifndef TWO
  108.      The Named is the mother of all things.
  109.      #else /* TWO */
  110.      The named is the mother of all things.
  111.      
  112.      #endif /* TWO */
  113.      Therefore let there always be non-being,
  114.        so we may see their subtlety,
  115.      And let there always be being,
  116.        so we may see their outcome.
  117.      The two are the same,
  118.      But after they are produced,
  119.        they have different names.
  120.      #ifdef TWO
  121.      They both may be called deep and profound.
  122.      Deeper and more profound,
  123.      The door of all subtleties!
  124.      #endif /* TWO */
  125. File: diff.info,  Node: Comparing Directories,  Next: Adjusting Output,  Prev: Output Formats,  Up: Top
  126. Comparing Directories
  127. *********************
  128.    You can use `diff' to compare some or all of the files in two
  129. directory trees.  When both file name arguments to `diff' are
  130. directories, it compares each file that is contained in both
  131. directories, examining file names in alphabetical order.  Normally
  132. `diff' is silent about pairs of files that contain no differences, but
  133. if you use the `-s' or `--report-identical-files' option, it reports
  134. pairs of identical files.  Normally `diff' reports subdirectories
  135. common to both directories without comparing subdirectories' files, but
  136. if you use the `-r' or `--recursive' option, it compares every
  137. corresponding pair of files in the directory trees, as many levels deep
  138. as they go.
  139.    For file names that are in only one of the directories, `diff'
  140. normally does not show the contents of the file that exists; it reports
  141. only that the file exists in that directory and not in the other.  You
  142. can make `diff' act as though the file existed but was empty in the
  143. other directory, so that it outputs the entire contents of the file that
  144. actually exists.  (It is output as either an insertion or a deletion,
  145. depending on whether it is in the first or the second directory given.)
  146. To do this, use the `-N' or `--new-file' option.
  147.    If the older directory contains one or more large files that are not
  148. in the newer directory, you can make the patch smaller by using the
  149. `-P' or `--unidirectional-new-file' option instead of `-N'.  This
  150. option is like `-N' except that it only inserts the contents of files
  151. that appear in the second directory but not the first (that is, files
  152. that were added).  At the top of the patch, write instructions for the
  153. user applying the patch to remove the files that were deleted before
  154. applying the patch.  *Note Making Patches::, for more discussion of
  155. making patches for distribution.
  156.    To ignore some files while comparing directories, use the `-x
  157. PATTERN' or `--exclude=PATTERN' option.  This option ignores any files
  158. or subdirectories whose base names match the shell pattern PATTERN.
  159. Unlike in the shell, a period at the start of the base of a file name
  160. matches a wildcard at the start of a pattern.  You should enclose
  161. PATTERN in quotes so that the shell does not expand it.  For example,
  162. the option `-x '*.[ao]'' ignores any file whose name ends with `.a' or
  163. `.o'.
  164.    This option accumulates if you specify it more than once.  For
  165. example, using the options `-x 'RCS' -x '*,v'' ignores any file or
  166. subdirectory whose base name is `RCS' or ends with `,v'.
  167.    If you need to give this option many times, you can instead put the
  168. patterns in a file, one pattern per line, and use the `-X FILE' or
  169. `--exclude-from=FILE' option.
  170.    If you have been comparing two directories and stopped partway
  171. through, later you might want to continue where you left off.  You can
  172. do this by using the `-S FILE' or `--starting-file=FILE' option.  This
  173. compares only the file FILE and all alphabetically later files in the
  174. topmost directory level.
  175. File: diff.info,  Node: Adjusting Output,  Next: diff Performance,  Prev: Comparing Directories,  Up: Top
  176. Making `diff' Output Prettier
  177. *****************************
  178.    `diff' provides several ways to adjust the appearance of its output.
  179. These adjustments can be applied to any output format.
  180. * Menu:
  181. * Tabs::        Preserving the alignment of tabstops.
  182. * Pagination::        Page numbering and timestamping `diff' output.
  183. File: diff.info,  Node: Tabs,  Next: Pagination,  Up: Adjusting Output
  184. Preserving Tabstop Alignment
  185. ============================
  186.    The lines of text in some of the `diff' output formats are preceded
  187. by one or two characters that indicate whether the text is inserted,
  188. deleted, or changed.  The addition of those characters can cause tabs to
  189. move to the next tabstop, throwing off the alignment of columns in the
  190. line.  GNU `diff' provides two ways to make tab-aligned columns line up
  191. correctly.
  192.    The first way is to have `diff' convert all tabs into the correct
  193. number of spaces before outputting them; select this method with the
  194. `-t' or `--expand-tabs' option.  `diff' assumes that tabstops are set
  195. every 8 columns.  To use this form of output with `patch', you must
  196. give `patch' the `-l' or `--ignore-whitespace' option (*note Changed
  197. Whitespace::., for more information).
  198.    The other method for making tabs line up correctly is to add a tab
  199. character instead of a space after the indicator character at the
  200. beginning of the line.  This ensures that all following tab characters
  201. are in the same position relative to tabstops that they were in the
  202. original files, so that the output is aligned correctly.  Its
  203. disadvantage is that it can make long lines too long to fit on one line
  204. of the screen or the paper.  It also does not work with the unified
  205. output format, which does not have a space character after the change
  206. type indicator character.  Select this method with the `-T' or
  207. `--initial-tab' option.
  208. File: diff.info,  Node: Pagination,  Prev: Tabs,  Up: Adjusting Output
  209. Paginating `diff' Output
  210. ========================
  211.    It can be convenient to have long output page-numbered and
  212. time-stamped.  The `-l' and `--paginate' options do this by sending the
  213. `diff' output through the `pr' program.  Here is what the page header
  214. might look like for `diff -lc lao tzu':
  215.      Mar 11 13:37 1991  diff -lc lao tzu Page 1
  216. File: diff.info,  Node: diff Performance,  Next: Comparing Three Files,  Prev: Adjusting Output,  Up: Top
  217. `diff' Performance Tradeoffs
  218. ****************************
  219.    GNU `diff' runs quite efficiently; however, in some circumstances
  220. you can cause it to run faster or produce a more compact set of changes.
  221. There are two ways that you can affect the performance of GNU `diff' by
  222. changing the way it compares files.
  223.    Performance has more than one dimension.  These options improve one
  224. aspect of performance at the cost of another, or they improve
  225. performance in some cases while hurting it in others.
  226.    The way that GNU `diff' determines which lines have changed always
  227. comes up with a near-minimal set of differences.  Usually it is good
  228. enough for practical purposes.  If the `diff' output is large, you
  229. might want `diff' to use a modified algorithm that sometimes produces a
  230. smaller set of differences.  The `-d' or `--minimal' option does this;
  231. however, it can also cause `diff' to run more slowly than usual, so it
  232. is not the default behavior.
  233.    When the files you are comparing are large and have small groups of
  234. changes scattered throughout them, you can use the `-H' or
  235. `--speed-large-files' option to make a different modification to the
  236. algorithm that `diff' uses.  If the input files have a constant small
  237. density of changes, this option speeds up the comparisons without
  238. changing the output.  If not, `diff' might produce a larger set of
  239. differences; however, the output will still be correct.
  240. File: diff.info,  Node: Comparing Three Files,  Next: diff3 Merging,  Prev: diff Performance,  Up: Top
  241. Comparing Three Files
  242. *********************
  243.    Use the program `diff3' to compare three files and show any
  244. differences among them.  (`diff3' can also merge files; see *Note diff3
  245. Merging::).
  246.    The "normal" `diff3' output format shows each hunk of differences
  247. without surrounding context.  Hunks are labeled depending on whether
  248. they are two-way or three-way, and lines are annotated by their
  249. location in the input files.
  250.    *Note Invoking diff3::, for more information on how to run `diff3'.
  251. * Menu:
  252. * Sample diff3 Input::        Sample `diff3' input for examples.
  253. * Detailed diff3 Normal::    A detailed description of normal output format.
  254. * diff3 Hunks::            The format of normal output format.
  255. * Example diff3 Normal::    Sample output in the normal format.
  256. File: diff.info,  Node: Sample diff3 Input,  Next: Detailed diff3 Normal,  Up: Comparing Three Files
  257. A Third Sample Input File
  258. =========================
  259.    Here is a third sample file that will be used in examples to
  260. illustrate the output of `diff3' and how various options can change it.
  261. The first two files are the same that we used for `diff' (*note Sample
  262. diff Input::.).  This is the third sample file, called `tao':
  263.      The Way that can be told of is not the eternal Way;
  264.      The name that can be named is not the eternal name.
  265.      The Nameless is the origin of Heaven and Earth;
  266.      The named is the mother of all things.
  267.      
  268.      Therefore let there always be non-being,
  269.        so we may see their subtlety,
  270.      And let there always be being,
  271.        so we may see their result.
  272.      The two are the same,
  273.      But after they are produced,
  274.        they have different names.
  275.      
  276.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  277. File: diff.info,  Node: Detailed diff3 Normal,  Next: diff3 Hunks,  Prev: Sample diff3 Input,  Up: Comparing Three Files
  278. Detailed Description of `diff3' Normal Format
  279. =============================================
  280.    Each hunk begins with a line marked `===='.  Three-way hunks have
  281. plain `====' lines, and two-way hunks have `1', `2', or `3' appended to
  282. specify which of the three input files differ in that hunk.  The hunks
  283. contain copies of two or three sets of input lines each preceded by one
  284. or two commands identifying where the lines came from.  Two spaces
  285. precede each copy of an input line to distinguish it from the commands.
  286. Commands take the following forms:
  287. `FILE:La'
  288.      This hunk appears after line L of file FILE, and contains no lines
  289.      in that file.  To edit this file to yield the other files, one
  290.      must append hunk lines taken from the other files.  For example,
  291.      `1:11a' means that the hunk follows line 11 in the first file and
  292.      contains no lines from that file.
  293. `FILE:Rc'
  294.      This hunk contains the lines in the range R of file FILE.  The
  295.      range R is a comma-separated pair of line numbers, or just one
  296.      number if the range is a singleton.  To edit this file to yield the
  297.      other files, one must change the specified lines to be the lines
  298.      taken from the other files.  For example, `2:11,13c' means that
  299.      the hunk contains lines 11 through 13 from the second file.
  300.    If the last line in a set of input lines is incomplete (*note
  301. Incomplete Lines::.), it is distinguished on output from a full line by
  302. a following line that starts with `\'.
  303. File: diff.info,  Node: diff3 Hunks,  Next: Example diff3 Normal,  Prev: Detailed diff3 Normal,  Up: Comparing Three Files
  304. `diff3' Hunks
  305. =============
  306.    Groups of lines that differ in two or three of the input files are
  307. called "diff3 hunks", by analogy with `diff' hunks (*note Hunks::.).
  308. If all three input files differ in a `diff3' hunk, the hunk is called a
  309. "three-way hunk"; if just two input files differ, it is a "two-way
  310. hunk".
  311.    As with `diff', several solutions are possible.  When comparing the
  312. files `A', `B', and `C', `diff3' normally finds `diff3' hunks by
  313. merging the two-way hunks output by the two commands `diff A B' and
  314. `diff A C'.  This does not necessarily minimize the size of the output,
  315. but exceptions should be rare.
  316.    For example, suppose `F' contains the three lines `a', `b', `f', `G'
  317. contains the lines `g', `b', `g', and `H' contains the lines `a', `b',
  318. `h'.  `diff3 F G H' might output the following:
  319.      ====2
  320.      1:1c
  321.      3:1c
  322.        a
  323.      2:1c
  324.        g
  325.      ====
  326.      1:3c
  327.        f
  328.      2:3c
  329.        g
  330.      3:3c
  331.        h
  332. because it found a two-way hunk containing `a' in the first and third
  333. files and `g' in the second file, then the single line `b' common to
  334. all three files, then a three-way hunk containing the last line of each
  335. file.
  336. File: diff.info,  Node: Example diff3 Normal,  Prev: diff3 Hunks,  Up: Comparing Three Files
  337. An Example of `diff3' Normal Format
  338. ===================================
  339.    Here is the output of the command `diff3 lao tzu tao' (*note Sample
  340. diff3 Input::., for the complete contents of the files).  Notice that
  341. it shows only the lines that are different among the three files.
  342.      ====2
  343.      1:1,2c
  344.      3:1,2c
  345.        The Way that can be told of is not the eternal Way;
  346.        The name that can be named is not the eternal name.
  347.      2:0a
  348.      ====1
  349.      1:4c
  350.        The Named is the mother of all things.
  351.      2:2,3c
  352.      3:4,5c
  353.        The named is the mother of all things.
  354.      
  355.      ====3
  356.      1:8c
  357.      2:7c
  358.          so we may see their outcome.
  359.      3:9c
  360.          so we may see their result.
  361.      ====
  362.      1:11a
  363.      2:11,13c
  364.        They both may be called deep and profound.
  365.        Deeper and more profound,
  366.        The door of all subtleties!
  367.      3:13,14c
  368.      
  369.          -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  370. File: diff.info,  Node: diff3 Merging,  Next: Interactive Merging,  Prev: Comparing Three Files,  Up: Top
  371. Merging From a Common Ancestor
  372. ******************************
  373.    When two people have made changes to copies of the same file,
  374. `diff3' can produce a merged output that contains both sets of changes
  375. together with warnings about conflicts.
  376.    One might imagine programs with names like `diff4' and `diff5' to
  377. compare more than three files simultaneously, but in practice the need
  378. rarely arises.  You can use `diff3' to merge three or more sets of
  379. changes to a file by merging two change sets at a time.
  380.    `diff3' can incorporate changes from two modified versions into a
  381. common preceding version.  This lets you merge the sets of changes
  382. represented by the two newer files.  Specify the common ancestor version
  383. as the second argument and the two newer versions as the first and third
  384. arguments, like this:
  385.      diff3 MINE OLDER YOURS
  386. You can remember the order of the arguments by noting that they are in
  387. alphabetical order.
  388.    You can think of this as subtracting OLDER from YOURS and adding the
  389. result to MINE, or as merging into MINE the changes that would turn
  390. OLDER into YOURS.  This merging is well-defined as long as MINE and
  391. OLDER match in the neighborhood of each such change.  This fails to be
  392. true when all three input files differ or when only OLDER differs; we
  393. call this a "conflict".  When all three input files differ, we call the
  394. conflict an "overlap".
  395.    `diff3' gives you several ways to handle overlaps and conflicts.
  396. You can omit overlaps or conflicts, or select only overlaps, or mark
  397. conflicts with special `<<<<<<<' and `>>>>>>>' lines.
  398.    `diff3' can output the merge results as an `ed' script that that can
  399. be applied to the first file to yield the merged output.  However, it
  400. is usually better to have `diff3' generate the merged output directly;
  401. this bypasses some problems with `ed'.
  402. * Menu:
  403. * Which Changes::        Selecting changes to incorporate.
  404. * Marking Conflicts::        Marking conflicts.
  405. * Bypassing ed::        Generating merged output directly.
  406. * Merging Incomplete Lines::    How `diff3' merges incomplete lines.
  407. * Saving the Changed File::    Emulating System V behavior.
  408. File: diff.info,  Node: Which Changes,  Next: Marking Conflicts,  Up: diff3 Merging
  409. Selecting Which Changes to Incorporate
  410. ======================================
  411.    You can select all unmerged changes from OLDER to YOURS for merging
  412. into MINE with the `-e' or `--ed' option.  You can select only the
  413. nonoverlapping unmerged changes with `-3' or `--easy-only', and you can
  414. select only the overlapping changes with `-x' or `--overlap-only'.
  415.    The `-e', `-3' and `-x' options select only "unmerged changes", i.e.
  416. changes where MINE and YOURS differ; they ignore changes from OLDER to
  417. YOURS where MINE and YOURS are identical, because they assume that such
  418. changes have already been merged.  If this assumption is not a safe
  419. one, you can use the `-A' or `--show-all' option (*note Marking
  420. Conflicts::.).
  421.    Here is the output of the command `diff3' with each of these three
  422. options (*note Sample diff3 Input::., for the complete contents of the
  423. files).  Notice that `-e' outputs the union of the disjoint sets of
  424. changes output by `-3' and `-x'.
  425.    Output of `diff3 -e lao tzu tao':
  426.      11a
  427.      
  428.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  429.      .
  430.      8c
  431.        so we may see their result.
  432.      .
  433.    Output of `diff3 -3 lao tzu tao':
  434.      8c
  435.        so we may see their result.
  436.      .
  437.    Output of `diff3 -x lao tzu tao':
  438.      11a
  439.      
  440.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  441.      .
  442. File: diff.info,  Node: Marking Conflicts,  Next: Bypassing ed,  Prev: Which Changes,  Up: diff3 Merging
  443. Marking Conflicts
  444. =================
  445.    `diff3' can mark conflicts in the merged output by bracketing them
  446. with special marker lines.  A conflict that comes from two files A and
  447. B is marked as follows:
  448.      <<<<<<< A
  449.      lines from A
  450.      =======
  451.      lines from B
  452.      >>>>>>> B
  453.    A conflict that comes from three files A, B and C is marked as
  454. follows:
  455.      <<<<<<< A
  456.      lines from A
  457.      ||||||| B
  458.      lines from B
  459.      =======
  460.      lines from C
  461.      >>>>>>> C
  462.    The `-A' or `--show-all' option acts like the `-e' option, except
  463. that it brackets conflicts, and it outputs all changes from OLDER to
  464. YOURS, not just the unmerged changes.  Thus, given the sample input
  465. files (*note Sample diff3 Input::.), `diff3 -A lao tzu tao' puts
  466. brackets around the conflict where only `tzu' differs:
  467.      <<<<<<< tzu
  468.      =======
  469.      The Way that can be told of is not the eternal Way;
  470.      The name that can be named is not the eternal name.
  471.      >>>>>>> tao
  472.    And it outputs the three-way conflict as follows:
  473.      <<<<<<< lao
  474.      ||||||| tzu
  475.      They both may be called deep and profound.
  476.      Deeper and more profound,
  477.      The door of all subtleties!
  478.      =======
  479.      
  480.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  481.      >>>>>>> tao
  482.    The `-E' or `--show-overlap' option outputs less information than
  483. the `-A' or `--show-all' option, because it outputs only unmerged
  484. changes, and it never outputs the contents of the second file.  Thus
  485. the `-E' option acts like the `-e' option, except that it brackets the
  486. first and third files from three-way overlapping changes.  Similarly,
  487. `-X' acts like `-x', except it brackets all its (necessarily
  488. overlapping) changes.  For example, for the three-way overlapping
  489. change above, the `-E' and `-X' options output the following:
  490.      <<<<<<< lao
  491.      =======
  492.      
  493.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  494.      >>>>>>> tao
  495.    If you are comparing files that have meaningless or uninformative
  496. names, you can use the `-L LABEL' or `--label=LABEL' option to show
  497. alternate names in the `<<<<<<<', `|||||||' and `>>>>>>>' brackets.
  498. This option can be given up to three times, once for each input file.
  499. Thus `diff3 -A -L X -L Y -L Z A B C' acts like `diff3 -A A B C', except
  500. that the output looks like it came from files named `X', `Y' and `Z'
  501. rather than from files named `A', `B' and `C'.
  502. File: diff.info,  Node: Bypassing ed,  Next: Merging Incomplete Lines,  Prev: Marking Conflicts,  Up: diff3 Merging
  503. Generating the Merged Output Directly
  504. =====================================
  505.    With the `-m' or `--merge' option, `diff3' outputs the merged file
  506. directly.  This is more efficient than using `ed' to generate it, and
  507. works even with non-text files that `ed' would reject.  If you specify
  508. `-m' without an `ed' script option, `-A' (`--show-all') is assumed.
  509.    For example, the command `diff3 -m lao tzu tao' (*note Sample diff3
  510. Input::. for a copy of the input files) would output the following:
  511.      <<<<<<< tzu
  512.      =======
  513.      The Way that can be told of is not the eternal Way;
  514.      The name that can be named is not the eternal name.
  515.      >>>>>>> tao
  516.      The Nameless is the origin of Heaven and Earth;
  517.      The Named is the mother of all things.
  518.      Therefore let there always be non-being,
  519.        so we may see their subtlety,
  520.      And let there always be being,
  521.        so we may see their result.
  522.      The two are the same,
  523.      But after they are produced,
  524.        they have different names.
  525.      <<<<<<< lao
  526.      ||||||| tzu
  527.      They both may be called deep and profound.
  528.      Deeper and more profound,
  529.      The door of all subtleties!
  530.      =======
  531.      
  532.        -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  533.      >>>>>>> tao
  534. File: diff.info,  Node: Merging Incomplete Lines,  Next: Saving the Changed File,  Prev: Bypassing ed,  Up: diff3 Merging
  535. How `diff3' Merges Incomplete Lines
  536. ===================================
  537.    With `-m', incomplete lines (*note Incomplete Lines::.) are simply
  538. copied to the output as they are found; if the merged output ends in an
  539. conflict and one of the input files ends in an incomplete line,
  540. succeeding `|||||||', `=======' or `>>>>>>>' brackets appear somewhere
  541. other than the start of a line because they are appended to the
  542. incomplete line.
  543.    Without `-m', if an `ed' script option is specified and an
  544. incomplete line is found, `diff3' generates a warning and acts as if a
  545. newline had been present.
  546. File: diff.info,  Node: Saving the Changed File,  Prev: Merging Incomplete Lines,  Up: diff3 Merging
  547. Saving the Changed File
  548. =======================
  549.    Traditional Unix `diff3' generates an `ed' script without the
  550. trailing `w' and and `q' commands that save the changes.  System V
  551. `diff3' generates these extra commands.  GNU `diff3' normally behaves
  552. like traditional Unix `diff3', but with the `-i' option it behaves like
  553. System V `diff3' and appends the `w' and `q' commands.
  554.    The `-i' option requires one of the `ed' script options `-AeExX3',
  555. and is incompatible with the merged output option `-m'.
  556. File: diff.info,  Node: Interactive Merging,  Next: Merging with patch,  Prev: diff3 Merging,  Up: Top
  557. Interactive Merging with `sdiff'
  558. ********************************
  559.    With `sdiff', you can merge two files interactively based on a
  560. side-by-side `-y' format comparison (*note Side by Side::.).  Use `-o
  561. FILE' or `--output=FILE' to specify where to put the merged text.
  562. *Note Invoking sdiff::, for more details on the options to `sdiff'.
  563.    Another way to merge files interactively is to use the Emacs Lisp
  564. package `emerge'.  *Note emerge: (emacs)emerge, for more information.
  565. * Menu:
  566. * sdiff Option Summary::Summary of `sdiff' options.
  567. * Merge Commands::    Merging two files interactively.
  568. File: diff.info,  Node: sdiff Option Summary,  Next: Merge Commands,  Up: Interactive Merging
  569. Specifying `diff' Options to `sdiff'
  570. ====================================
  571.    The following `sdiff' options have the same meaning as for `diff'.
  572. *Note diff Options::, for the use of these options.
  573.      -a -b -d -i -t -v
  574.      -B -H -I REGEXP
  575.      
  576.      --ignore-blank-lines  --ignore-case
  577.      --ignore-matching-lines=REGEXP  --ignore-space-change
  578.      --left-column  --minimal  --speed-large-files
  579.      --suppress-common-lines  --expand-tabs
  580.      --text  --version  --width=COLUMNS
  581.    For historical reasons, `sdiff' has alternate names for some
  582. options.  The `-l' option is equivalent to the `--left-column' option,
  583. and similarly `-s' is equivalent to `--suppress-common-lines'.  The
  584. meaning of the `sdiff' `-w' and `-W' options is interchanged from that
  585. of `diff': with `sdiff', `-w COLUMNS' is equivalent to
  586. `--width=COLUMNS', and `-W' is equivalent to `--ignore-all-space'.
  587. `sdiff' without the `-o' option is equivalent to `diff' with the `-y'
  588. or `--side-by-side' option (*note Side by Side::.).
  589. File: diff.info,  Node: Merge Commands,  Prev: sdiff Option Summary,  Up: Interactive Merging
  590. Merge Commands
  591. ==============
  592.    Groups of common lines, with a blank gutter, are copied from the
  593. first file to the output.  After each group of differing lines, `sdiff'
  594. prompts with `%' and pauses, waiting for one of the following commands.
  595. Follow each command with RET.
  596.      Discard both versions.  Invoke a text editor on an empty temporary
  597.      file, then copy the resulting file to the output.
  598.      Concatenate the two versions, edit the result in a temporary file,
  599.      then copy the edited result to the output.
  600.      Edit a copy of the left version, then copy the result to the
  601.      output.
  602.      Edit a copy of the right version, then copy the result to the
  603.      output.
  604.      Copy the left version to the output.
  605.      Quit.
  606.      Copy the right version to the output.
  607.      Silently copy common lines.
  608.      Verbosely copy common lines.  This is the default.
  609.    The text editor invoked is specified by the `EDITOR' environment
  610. variable if it is set.  The default is system-dependent.
  611. File: diff.info,  Node: Merging with patch,  Next: Making Patches,  Prev: Interactive Merging,  Up: Top
  612. Merging with `patch'
  613. ********************
  614.    `patch' takes comparison output produced by `diff' and applies the
  615. differences to a copy of the original file, producing a patched
  616. version.  With `patch', you can distribute just the changes to a set of
  617. files instead of distributing the entire file set; your correspondents
  618. can apply `patch' to update their copy of the files with your changes.
  619. `patch' automatically determines the diff format, skips any leading or
  620. trailing headers, and uses the headers to determine which file to
  621. patch.  This lets your correspondents feed an article or message
  622. containing a difference listing directly to `patch'.
  623.    `patch' detects and warns about common problems like forward
  624. patches.  It saves the original version of the files it patches, and
  625. saves any patches that it could not apply.  It can also maintain a
  626. `patchlevel.h' file to ensures that your correspondents apply diffs in
  627. the proper order.
  628.    `patch' accepts a series of diffs in its standard input, usually
  629. separated by headers that specify which file to patch.  It applies
  630. `diff' hunks (*note Hunks::.) one by one.  If a hunk does not exactly
  631. match the original file, `patch' uses heuristics to try to patch the
  632. file as well as it can.  If no approximate match can be found, `patch'
  633. rejects the hunk and skips to the next hunk.  `patch' normally replaces
  634. each file F with its new version, saving the original file in `F.orig',
  635. and putting reject hunks (if any) into `F.rej'.
  636.    *Note Invoking patch::, for detailed information on the options to
  637. `patch'.  *Note Backups::, for more information on how `patch' names
  638. backup files.  *Note Rejects::, for more information on where `patch'
  639. puts reject hunks.
  640. * Menu:
  641. * patch Input::        Selecting the type of `patch' input.
  642. * Imperfect::        Dealing with imperfect patches.
  643. * Empty Files::        Removing empty files after patching.
  644. * Multiple Patches::    Handling multiple patches in a file specially.
  645. * patch Messages::    Messages and questions `patch' can produce.
  646. File: diff.info,  Node: patch Input,  Next: Imperfect,  Up: Merging with patch
  647. Selecting the `patch' Input Format
  648. ==================================
  649.    `patch' normally determines which `diff' format the patch file uses
  650. by examining its contents.  For patch files that contain particularly
  651. confusing leading text, you might need to use one of the following
  652. options to force `patch' to interpret the patch file as a certain
  653. format of diff.  The output formats listed here are the only ones that
  654. `patch' can understand.
  655. `--context'
  656.      context diff.
  657. `--ed'
  658.      `ed' script.
  659. `--normal'
  660.      normal diff.
  661. `--unified'
  662.      unified diff.
  663. File: diff.info,  Node: Imperfect,  Next: Empty Files,  Prev: patch Input,  Up: Merging with patch
  664. Applying Imperfect Patches
  665. ==========================
  666.    `patch' tries to skip any leading text in the patch file, apply the
  667. diff, and then skip any trailing text.  Thus you can feed a news article
  668. or mail message directly to `patch', and it should work.  If the entire
  669. diff is indented by a constant amount of whitespace, `patch'
  670. automatically ignores the indentation.
  671.    However, certain other types of imperfect input require user
  672. intervention.
  673. * Menu:
  674. * Changed Whitespace::    When tabs and spaces don't match exactly.
  675. * Reversed Patches::    Applying reversed patches correctly.
  676. * Inexact::        Helping `patch' find close matches.
  677. File: diff.info,  Node: Changed Whitespace,  Next: Reversed Patches,  Up: Imperfect
  678. Applying Patches with Changed Whitespace
  679. ----------------------------------------
  680.    Sometimes mailers, editors, or other programs change spaces into
  681. tabs, or vice versa.  If this happens to a patch file or an input file,
  682. the files might look the same, but `patch' will not be able to match
  683. them properly.  If this problem occurs, use the `-l' or
  684. `--ignore-whitespace' option, which makes `patch' compare whitespace
  685. loosely so that any sequence of whitespace in the patch file matches
  686. any sequence of whitespace in the input files.  Non-whitespace
  687. characters must still match exactly.  Each line of the context must
  688. still match a line in the input file.
  689. File: diff.info,  Node: Reversed Patches,  Next: Inexact,  Prev: Changed Whitespace,  Up: Imperfect
  690. Applying Reversed Patches
  691. -------------------------
  692.    Sometimes people run `diff' with the new file first instead of
  693. second.  This creates a diff that is "reversed".  To apply such
  694. patches, give `patch' the `-R' or `--reverse' option.  `patch' then
  695. attempts to swap each hunk around before applying it.  Rejects come out
  696. in the swapped format.  The `-R' option does not work with `ed' scripts
  697. because there is too little information in them to reconstruct the
  698. reverse operation.
  699.    Often `patch' can guess that the patch is reversed.  If the first
  700. hunk of a patch fails, `patch' reverses the hunk to see if it can apply
  701. it that way.  If it can, `patch' asks you if you want to have the `-R'
  702. option set; if it can't, `patch' continues to apply the patch normally.
  703. This method cannot detect a reversed patch if it is a normal diff and
  704. the first command is an append (which should have been a delete) since
  705. appends always succeed, because a null context matches anywhere.  But
  706. most patches add or change lines rather than delete them, so most
  707. reversed normal diffs begin with a delete, which fails, and `patch'
  708. notices.
  709.    If you apply a patch that you have already applied, `patch' thinks
  710. it is a reversed patch and offers to un-apply the patch.  This could be
  711. construed as a feature.  If you did this inadvertently and you don't
  712. want to un-apply the patch, just answer `n' to this offer and to the
  713. subsequent "apply anyway" question--or type `C-c' to kill the `patch'
  714. process.
  715. File: diff.info,  Node: Inexact,  Prev: Reversed Patches,  Up: Imperfect
  716. Helping `patch' Find Inexact Matches
  717. ------------------------------------
  718.    For context diffs, and to a lesser extent normal diffs, `patch' can
  719. detect when the line numbers mentioned in the patch are incorrect, and
  720. it attempts to find the correct place to apply each hunk of the patch.
  721. As a first guess, it takes the line number mentioned in the hunk, plus
  722. or minus any offset used in applying the previous hunk.  If that is not
  723. the correct place, `patch' scans both forward and backward for a set of
  724. lines matching the context given in the hunk.
  725.    First `patch' looks for a place where all lines of the context
  726. match.  If it cannot find such a place, and it is reading a context or
  727. unified diff, and the maximum fuzz factor is set to 1 or more, then
  728. `patch' makes another scan, ignoring the first and last line of
  729. context.  If that fails, and the maximum fuzz factor is set to 2 or
  730. more, it makes another scan, ignoring the first two and last two lines
  731. of context are ignored.  It continues similarly if the maximum fuzz
  732. factor is larger.
  733.    The `-F LINES' or `--fuzz=LINES' option sets the maximum fuzz factor
  734. to LINES.  This option only applies to context and unified diffs; it
  735. ignores up to LINES lines while looking for the place to install a
  736. hunk.  Note that a larger fuzz factor increases the odds of making a
  737. faulty patch.  The default fuzz factor is 2; it may not be set to more
  738. than the number of lines of context in the diff, ordinarily 3.
  739.    If `patch' cannot find a place to install a hunk of the patch, it
  740. writes the hunk out to a reject file (*note Rejects::., for information
  741. on how reject files are named).  It writes out rejected hunks in context
  742. format no matter what form the input patch is in.  If the input is a
  743. normal or `ed' diff, many of the contexts are simply null.  The line
  744. numbers on the hunks in the reject file may be different from those in
  745. the patch file: they show the approximate location where `patch' thinks
  746. the failed hunks belong in the new file rather than in the old one.
  747.    As it completes each hunk, `patch' tells you whether the hunk
  748. succeeded or failed, and if it failed, on which line (in the new file)
  749. `patch' thinks the hunk should go.  If this is different from the line
  750. number specified in the diff, it tells you the offset.  A single large
  751. offset *may* indicate that `patch' installed a hunk in the wrong place.
  752. `patch' also tells you if it used a fuzz factor to make the match, in
  753. which case you should also be slightly suspicious.
  754.    `patch' cannot tell if the line numbers are off in an `ed' script,
  755. and can only detect wrong line numbers in a normal diff when it finds a
  756. change or delete command.  It may have the same problem with a context
  757. diff using a fuzz factor equal to or greater than the number of lines
  758. of context shown in the diff (typically 3).  In these cases, you should
  759. probably look at a context diff between your original and patched input
  760. files to see if the changes make sense.  Compiling without errors is a
  761. pretty good indication that the patch worked, but not a guarantee.
  762.    `patch' usually produces the correct results, even when it must make
  763. many guesses.  However, the results are guaranteed only when the patch
  764. is applied to an exact copy of the file that the patch was generated
  765. from.
  766. File: diff.info,  Node: Empty Files,  Next: Multiple Patches,  Prev: Imperfect,  Up: Merging with patch
  767. Removing Empty Files
  768. ====================
  769.    Sometimes when comparing two directories, the first directory
  770. contains a file that the second directory does not.  If you give `diff'
  771. the `-N' or `--new-file' option, it outputs a diff that deletes the
  772. contents of this file.  By default, `patch' leaves an empty file after
  773. applying such a diff.  The `-E' or `--remove-empty-files' option to
  774. `patch' deletes output files that are empty after applying the diff.
  775. File: diff.info,  Node: Multiple Patches,  Next: patch Messages,  Prev: Empty Files,  Up: Merging with patch
  776. Multiple Patches in a File
  777. ==========================
  778.    If the patch file contains more than one patch, `patch' tries to
  779. apply each of them as if they came from separate patch files.  This
  780. means that it determines the name of the file to patch for each patch,
  781. and that it examines the leading text before each patch for file names
  782. and prerequisite revision level (*note Making Patches::., for more on
  783. that topic).
  784.    For the second and subsequent patches in the patch file, you can give
  785. options and another original file name by separating their argument
  786. lists with a `+'.  However, the argument list for a second or
  787. subsequent patch may not specify a new patch file, since that does not
  788. make sense.
  789.    For example, to tell `patch' to strip the first three slashes from
  790. the name of the first patch in the patch file and none from subsequent
  791. patches, and to use `code.c' as the first input file, you can use:
  792.      patch -p3 code.c + -p0 < patchfile
  793.    The `-S' or `--skip' option ignores the current patch from the patch
  794. file, but continue looking for the next patch in the file.  Thus, to
  795. ignore the first and third patches in the patch file, you can use:
  796.      patch -S + + -S + < patch file
  797. File: diff.info,  Node: patch Messages,  Prev: Multiple Patches,  Up: Merging with patch
  798. Messages and Questions from `patch'
  799. ===================================
  800.    `patch' can produce a variety of messages, especially if it has
  801. trouble decoding its input.  In a few situations where it's not sure how
  802. to proceed, `patch' normally prompts you for more information from the
  803. keyboard.  There are options to suppress printing non-fatal messages
  804. and stopping for keyboard input.
  805.    The message `Hmm...' indicates that `patch' is reading text in the
  806. patch file, attempting to determine whether there is a patch in that
  807. text, and if so, what kind of patch it is.
  808.    You can inhibit all terminal output from `patch', unless an error
  809. occurs, by using the `-s', `--quiet', or `--silent' option.
  810.    There are two ways you can prevent `patch' from asking you any
  811. questions.  The `-f' or `--force' option assumes that you know what you
  812. are doing.  It assumes the following:
  813.    * skip patches for which it can't find a file to patch;
  814.    * patch files even though they have the wrong version for the
  815.      `Prereq:' line in the patch;
  816.    * assume that patches are not reversed even if they look like they
  817.      are.
  818.    The `-t' or `--batch' option is similar to `-f', in that it
  819. suppresses questions, but it makes somewhat different assumptions:
  820.    * skip patches for which it can't find a file to patch (the same as
  821.      `-f');
  822.    * skip patches for which the file has the wrong version for the
  823.      `Prereq:' line in the patch;
  824.    * assume that patches are reversed if they look like they are.
  825.    `patch' exits with a non-zero status if it creates any reject files.
  826. When applying a set of patches in a loop, you should check the exit
  827. status, so you don't apply a later patch to a partially patched file.
  828. File: diff.info,  Node: Making Patches,  Next: Invoking cmp,  Prev: Merging with patch,  Up: Top
  829. Tips for Making Patch Distributions
  830. ***********************************
  831.    Here are some things you should keep in mind if you are going to
  832. distribute patches for updating a software package.
  833.    Make sure you have specified the file names correctly, either in a
  834. context diff header or with an `Index:' line.  If you are patching
  835. files in a subdirectory, be sure to tell the patch user to specify a
  836. `-p' or `--strip' option as needed.  Take care to not send out reversed
  837. patches, since these make people wonder whether they have already
  838. applied the patch.
  839.    To save people from partially applying a patch before other patches
  840. that should have gone before it, you can make the first patch in the
  841. patch file update a file with a name like `patchlevel.h' or
  842. `version.c', which contains a patch level or version number.  If the
  843. input file contains the wrong version number, `patch' will complain
  844. immediately.
  845.    An even clearer way to prevent this problem is to put a `Prereq:'
  846. line before the patch.  If the leading text in the patch file contains a
  847. line that starts with `Prereq:', `patch' takes the next word from that
  848. line (normally a version number) and checks whether the next input file
  849. contains that word, preceded and followed by either whitespace or a
  850. newline.  If not, `patch' prompts you for confirmation before
  851. proceeding.  This makes it difficult to accidentally apply patches in
  852. the wrong order.
  853.    Since `patch' does not handle incomplete lines properly, make sure
  854. that all the source files in your program end with a newline whenever
  855. you release a version.
  856.    To create a patch that changes an older version of a package into a
  857. newer version, first make a copy of the older version in a scratch
  858. directory.  Typically you do that by unpacking a `tar' or `shar'
  859. archive of the older version.
  860.    You might be able to reduce the size of the patch by renaming or
  861. removing some files before making the patch.  If the older version of
  862. the package contains any files that the newer version does not, or if
  863. any files have been renamed between the two versions, make a list of
  864. `rm' and `mv' commands for the user to execute in the old version
  865. directory before applying the patch.  Then run those commands yourself
  866. in the scratch directory.
  867.    If there are any files that you don't need to include in the patch
  868. because they can easily be rebuilt from other files (for example,
  869. `TAGS' and output from `yacc' and `makeinfo'), replace the versions in
  870. the scratch directory with the newer versions, using `rm' and `ln' or
  871. `cp'.
  872.    Now you can create the patch.  The de-facto standard `diff' format
  873. for patch distributions is context format with two lines of context,
  874. produced by giving `diff' the `-C 2' option.  Give `diff' the `-N'
  875. option in case the newer version of the package contains any files that
  876. the older one does not.  Make sure to specify the scratch directory
  877. first and the newer directory second.
  878.    Add to the top of the patch a note telling the user any `rm' and
  879. `mv' commands to run before applying the patch.  Then you can remove
  880. the scratch directory.
  881. File: diff.info,  Node: Invoking cmp,  Next: Invoking diff,  Prev: Making Patches,  Up: Top
  882. Invoking `cmp'
  883. **************
  884.    The `cmp' command compares two files, and if they differ, tells the
  885. first byte and line number where they differ.  Its arguments are as
  886. follows:
  887.      cmp OPTIONS... FROM-FILE [TO-FILE]
  888.    The file name `-' is always the standard input.  `cmp' also uses the
  889. standard input if one file name is omitted.
  890.    An exit status of 0 means no differences were found, 1 means some
  891. differences were found, and 2 means trouble.
  892. * Menu:
  893. * cmp Options::        Summary of options to `cmp'.
  894. File: diff.info,  Node: cmp Options,  Up: Invoking cmp
  895. Options to `cmp'
  896. ================
  897.    Below is a summary of all of the options that GNU `cmp' accepts.
  898. Most options have two equivalent names, one of which is a single letter
  899. preceded by `-', and the other of which is a long name preceded by
  900. `--'.  Multiple single letter options (unless they take an argument)
  901. can be combined into a single command line word: `-cl' is equivalent to
  902. `-c -l'.
  903.      Print the differing characters.  Display control characters as a
  904.      `^' followed by a letter of the alphabet and precede characters
  905.      that have the high bit set with `M-' (which stands for "meta").
  906.      Print the (decimal) offsets and (octal) values of all differing
  907.      bytes.
  908. `--print-chars'
  909.      Print the differing characters.  Display control characters as a
  910.      `^' followed by a letter of the alphabet and precede characters
  911.      that have the high bit set with `M-' (which stands for "meta").
  912. `--quiet'
  913. `--silent'
  914.      Do not print anything; only return an exit status indicating
  915.      whether the files differ.
  916. `--verbose'
  917.      Print the (decimal) offsets and (octal) values of all differing
  918.      bytes.
  919. File: diff.info,  Node: Invoking diff,  Next: Invoking diff3,  Prev: Invoking cmp,  Up: Top
  920. Invoking `diff'
  921. ***************
  922.    The format for running the `diff' command is:
  923.      diff OPTIONS... FROM-FILE TO-FILE
  924.    In the simplest case, `diff' compares the contents of the two files
  925. FROM-FILE and TO-FILE.  A file name of `-' stands for text read from
  926. the standard input.  As a special case, `diff - -' compares a copy of
  927. standard input to itself.
  928.    If FROM-FILE is a directory and TO-FILE is not, `diff' compares the
  929. file in FROM-FILE whose file name is that of TO-FILE, and vice versa.
  930. The non-directory file must not be `-'.
  931.    If both FROM-FILE and TO-FILE are directories, `diff' compares
  932. corresponding files in both directories, in alphabetical order; this
  933. comparison is not recursive unless the `-r' or `--recursive' option is
  934. given.  `diff' never compares the actual contents of a directory as if
  935. it were a file.  The file that is fully specified may not be standard
  936. input, because standard input is nameless and the notion of "file with
  937. the same name" does not apply.
  938.    `diff' options begin with `-', so normally FROM-FILE and TO-FILE may
  939. not begin with `-'.  However, `--' as an argument by itself treats the
  940. remaining arguments as file names even if they begin with `-'.
  941.    An exit status of 0 means no differences were found, 1 means some
  942. differences were found, and 2 means trouble.
  943. * Menu:
  944. * diff Options::    Summary of options to `diff'.
  945.